from langchain_community.tools.tavily_search import TavilySearchResults
import json
import os
from dotenv import load_dotenv

load_dotenv()

def search(query):
    daily = TavilySearchResults(max_results=5)
    try:
        ret = daily.invoke(input=query)
        print("搜索结果:{}".format(ret))
        print("\n")
        content_list = []
        for obj in ret:
            content_list.append(obj["content"])
        return "\n".join(content_list)
    except Exception as e:
        return "search error:{}".format(e)
    

if __name__ == '__main__':
    print(search("深圳天气怎么样"))